package test.sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Person {
	private String name;
	private Integer order;

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the order
	 */
	public Integer getOrder() {
		return order;
	}

	/**
	 * @param order
	 *            the order to set
	 */
	public void setOrder(Integer order) {
		this.order = order;
	}

	public static void main(String[] args) {
		List<Person> listA = new ArrayList<Person>();
		Person p1 = new Person();
		Person p2 = new Person();
		Person p3 = new Person();
		Person p4 = new Person();
		
		p1.setName("name1");
		p1.setOrder(1);
		p2.setName("name2");
		p2.setOrder(2);
		p3.setName("name3");
		p3.setOrder(3);
		p4.setName("name4");
		p4.setOrder(Integer.MAX_VALUE);

		listA.add(p2);
		listA.add(p1);
		listA.add(p3);
		listA.add(p4);

		Collections.sort(listA, new Comparator<Person>() {
			public int compare(Person p1, Person p2) {
				return p2.getOrder() - p1.getOrder();
			}
		});

		for (Person p : listA) {
			System.out.println(p.getName());
		}
	}

}